﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace LDSP.Util
{
    public class LDSPCookie
    {
        int expireDays = 30;
        static LDSPCookie _myCookie = null;

        public static LDSPCookie GetInstance()
        {
            if (_myCookie == null)
            {
                _myCookie = new LDSPCookie();
            }

            return _myCookie;
        }

        public void WriteCookie(HttpResponse response, string name, string value)
        {
            HttpCookie cookie = new HttpCookie(name, value);//"username" cookie名称
            cookie.Expires = DateTime.Now.AddDays(expireDays);//设置过期天数
            response.Cookies.Add(cookie);//将cookie写入客户端
        }

        public string GetCookie(HttpRequest request, string key)
        {
            HttpCookie cookie = request.Cookies[key];
            string username = string.Empty;
            if (cookie != null)
            {
                username = cookie.Value.ToString();//获取用户名
            }

            return username;
        }
    }
}
